<template>
  <a-drawer
      :title="title"
      :width="800"
      placement="right"
      :closable="false"
      @close="close"
      :visible="visible"
  >

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
      
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="互动信息ID">
          <a-input placeholder="请输入互动信息ID" v-decorator="['companyinteractiveid', validatorRules.companyinteractiveid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="公司ID">
          <a-input placeholder="请输入公司ID" v-decorator="['companyid', validatorRules.companyid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="互动类型">
          <a-input placeholder="请输入互动类型" v-decorator="['interactivetypeid', validatorRules.interactivetypeid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="互动日期">
          <a-input placeholder="请输入互动日期" v-decorator="['interactivedate', validatorRules.interactivedate ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="互动主题">
          <a-input placeholder="请输入互动主题" v-decorator="['interactivetheme', validatorRules.interactivetheme ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="互动目的">
          <a-input placeholder="请输入互动目的" v-decorator="['interactiveobjective', validatorRules.interactiveobjective ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="">
          <a-input placeholder="请输入" v-decorator="['interactiveaddressv', validatorRules.interactiveaddressv ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="拜访对象">
          <a-input placeholder="请输入拜访对象" v-decorator="['visitors', validatorRules.visitors ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="需求标签">
          <a-input placeholder="请输入需求标签" v-decorator="['demandtagid', validatorRules.demandtagid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="互动地点">
          <a-input placeholder="请输入互动地点" v-decorator="['interactiveaddress', validatorRules.interactiveaddress ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="需求描述">
          <a-input placeholder="请输入需求描述" v-decorator="['demanddescription', validatorRules.demanddescription ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="其它备注">
          <a-input placeholder="请输入其它备注" v-decorator="['remarks', validatorRules.remarks ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="Linker">
          <a-input placeholder="请输入Linker" v-decorator="['linkerid', validatorRules.linkerid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="最近更新人">
          <a-input placeholder="请输入最近更新人" v-decorator="['updatebyid', validatorRules.updatebyid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="最近更新日期">
          <a-input placeholder="请输入最近更新日期" v-decorator="['ts', validatorRules.ts ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="状态">
          <a-input placeholder="请输入状态" v-decorator="['datastatus', validatorRules.datastatus ]" />
        </a-form-item>
		
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "CompanyInteractiveModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        companyinteractiveid:{rules: [{ required: true, message: '请输入互动信息ID!' }]},
        companyid:{rules: [{ required: true, message: '请输入公司ID!' }]},
        interactivetypeid:{rules: [{ required: true, message: '请输入互动类型!' }]},
        interactivedate:{rules: [{ required: true, message: '请输入互动日期!' }]},
        interactivetheme:{rules: [{ required: true, message: '请输入互动主题!' }]},
        interactiveobjective:{rules: [{ required: true, message: '请输入互动目的!' }]},
        interactiveaddressv:{rules: [{ required: true, message: '请输入!' }]},
        visitors:{rules: [{ required: true, message: '请输入拜访对象!' }]},
        demandtagid:{rules: [{ required: true, message: '请输入需求标签!' }]},
        interactiveaddress:{rules: [{ required: true, message: '请输入互动地点!' }]},
        demanddescription:{rules: [{ required: true, message: '请输入需求描述!' }]},
        remarks:{rules: [{ required: true, message: '请输入其它备注!' }]},
        linkerid:{rules: [{ required: true, message: '请输入Linker!' }]},
        updatebyid:{rules: [{ required: true, message: '请输入最近更新人!' }]},
        ts:{rules: [{ required: true, message: '请输入最近更新日期!' }]},
        datastatus:{rules: [{ required: true, message: '请输入状态!' }]},
        },
        url: {
          add: "/robot/companyInteractive/add",
          edit: "/robot/companyInteractive/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'companyinteractiveid','companyid','interactivetypeid','interactivedate','interactivetheme','interactiveobjective','interactiveaddressv','visitors','demandtagid','interactiveaddress','demanddescription','remarks','linkerid','updatebyid','ts','datastatus'))
		  //时间格式化
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              // that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>